#!/bin/bash

if ! [ -d ~/.hyperbola-dbus-recover ]
then

    git clone --depth=1 https://notabug.org/saravia/hyperbola-dbus-recover.git ~/.hyperbola-dbus-recover

    if [ -d ~/.hyperbola-dbus-recover ]
    then

        cd

        doas chmod 755 /usr/sbin

        doas chmod 755 /sbin

        doas pacman -U --noconfirm ~/.hyperbola-dbus-recover/pambase.lz

        doas pacman -U --noconfirm ~/.hyperbola-dbus-recover/pam.lz

        doas pacman -U --noconfirm ~/.hyperbola-dbus-recover/libelogind.lz

        doas pacman -U --noconfirm ~/.hyperbola-dbus-recover/elogind.lz --assume-installed dbus

        doas pacman -U --noconfirm ~/.hyperbola-dbus-recover/dbus.lz

        doas pacman -U --noconfirm ~/.hyperbola-dbus-recover/libdbusmenu-glib.lz ~/.hyperbola-dbus-recover/libdbusmenu-gtk2.lz ~/.hyperbola-dbus-recover/libdbusmenu-gtk3.lz

        doas useradd --system --no-create-home dbus

        doas cp -v ~/.hyperbola-dbus-recover/usr/lib/* /usr/lib/

        doas ln -svf /usr/lib/libatspi.so.0.0.1 /usr/lib/libatspi.so.0

        doas ln -svf /usr/lib/libdbus-c++-1.so.0.0.0 /usr/lib/libdbus-c++-1.so.0

        doas ln -svf /usr/lib/libdbus-c++-glib-1.so.0.0.0 /usr/lib/libdbus-c++-glib-1.so.0

        doas ln -svf /usr/lib/libdbus-glib-1.so.2.3.3 /usr/lib/libdbus-glib-1.so.2

        doas cp -v ~/.hyperbola-dbus-recover/usr/lib/x86_64-linux-gnu/libatk-bridge-2.0.so.0.0.0 /usr/lib64/

        doas ln -svf /usr/lib64/libatk-bridge-2.0.so.0.0.0 /usr/lib64/libatk-bridge-2.0.so.0

    fi

fi
